from rest_framework.request import Request
from rest_framework.response import Response

from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases import ProjectEndpoint
from sentry.api.serializers import serialize
from sentry.grouping.strategies.configurations import GROUPING_CONFIG_CLASSES


@region_silo_endpoint
class ProjectGroupingConfigsEndpoint(ProjectEndpoint):
    owner = ApiOwner.ISSUES
    publish_status = {
        "GET": ApiPublishStatus.PRIVATE,
    }
    """
    Retrieve available grouping configs with project-specific information
    """

    def get(self, request: Request, project) -> Response:
        configs = [
            config.as_dict()
            for config in sorted(GROUPING_CONFIG_CLASSES.values(), key=lambda x: str(x.id))
        ]

        return Response(serialize(configs))
